#define _CRT_SECURE_NO_WARNINGS

#include "game.h"

void ClBoard(char board[ROW][COL], int row, int col)
{
	int i;
	int j;
	for (i = 0; i < row; i++)
	{
		for (j = 0; j < col; j++)
		{
			board[i][j] = ' ';
		}
	}
}

void PrBoard(char board[ROW][COL], int row, int col)
{
	int i;
	int j;
	printf(" ");
	for (i = 0; i < col; i++)
	{
		printf(" %d ", i + 1);
		if (i < col - 1)
			printf(" ");
	}
	printf("\n");
	for (i = 0; i < row; i++)
	{
		printf("%d", i + 1);
		for (j = 0; j < col; j++)
		{
			printf(" %c ", board[i][j]);
			if (j < col - 1)
				printf("|");
		}
		printf("\n");
		if (i < row - 1)
		{
			printf(" ");
			for (j = 0; j < col; j++)
			{
				printf("---");
				if (j < col - 1)
					printf("|");
			}
		}
		printf("\n");
	}
}

char IsWin(char board[ROW][COL], int row, int col)
{
	int i, j, sign = 0;
	for (i = 0; i < row; i++)
	{
		for (j = 0; j < col; j++)
		{
			if (board[i][j] != ' ')
				sign++;
			if (board[i][j] == board[i][j + 1] && board[i][j + 1] == board[i][j + 2] && board[i][j] != ' ')
				return board[i][j];
			if (board[i][j] == board[i + 1][j] && board[i + 1][j] == board[i + 2][j] && board[i][j] != ' ')
				return board[i][j];
			if (board[i][j] == board[i + 1][j + 1] && board[i + 1][j + 1] == board[i + 2][j + 1] && board[i][j] != ' ')
				return board[i][j];
			if (board[i][j] == board[i - 1][j - 1] && board[i - 1][j - 1] == board[i - 2][j - 1] && board[i][j] != ' ')
				return board[i][j];
		}
	}
	if (sign == row * col)
		return 'Q';
	return 'C';
}